package 并发编程12.CountDownLatch模块;

import java.util.concurrent.CountDownLatch;

/**
 * @author idea
 * @data 2019/2/24
 */
class Waiting implements Runnable{

    private CountDownLatch countDownLatch;

    public Waiting(CountDownLatch countDownLatch){
        this.countDownLatch=countDownLatch;
    }

    @Override
    public void run() {
        try {
            countDownLatch.await();
            System.out.println("执行----");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

public class Demo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch=new CountDownLatch(1);
        for(int i=0;i<5;i++){
            Thread thread=new Thread(new Waiting(countDownLatch));
            thread.start();
        }
        countDownLatch.countDown();
//        while(countDownLatch.getCount()!=0){
//            Thread.sleep(100);
//        }
        CountDownLatch countDownLatch2=new CountDownLatch(1);
        for(int i=0;i<5;i++){
            Thread thread=new Thread(new Waiting(countDownLatch2));
            thread.start();
        }
        countDownLatch2.countDown();
    }
}
